#!/bin/bash
#本脚本适用于CentOS/Redhat(release5&6版本)
#本脚本php5.3+Mysql  mysql root密码为空
#
#

#Network Test
ping -c 1 -t 1 www.baidu.com >/dev/null 2>&1
if [[ \$? == 2 ]]; then
    echo "nameserver 114.114.114.114
nameserver 8.8.8.8" > /etc/resolv.conf
fi
ping -c 1 -t 1 www.baidu.com >/dev/null 2>&1
if [[ $? == 2 ]]; then
    echo "Network problems,Please check!"
    exit
fi
OS=`cat /etc/redhat-release |awk ' {print $1$(NF-1)}'|cut -d . -f 1`
modify_rhel5_yum()
{
cat >/etc/yum.repos.d/CentOS-Base.repo  <<EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-\$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/5/os/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-\$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/5/updates/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-\$releasever - Addons - 163.com
baseurl=http://mirrors.163.com/centos/5/addons/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=addons
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-\$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/5/extras/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/5/centosplus/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-\$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/5/contrib/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
EOF
yum clean metadata
yum makecache
cd ~
}

modify_rhel6_yum()
{
cat >/etc/yum.repos.d/CentOS-Base.repo  <<EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-\$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-\$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-\\$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-\\$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/6/centosplus/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-\\$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/6/contrib/\$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=\$releasever&arch=\$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
EOF
yum clean metadata
yum makecache
cd ~
}
case "$OS" in
Red5|CentOS5)
modify_rhel5_yum
;;
Red6|CentOS6)
modify_rhel6_yum
;;
*)
echo "Unknown system"
;;
esac
case "$OS" in
Red5|CentOS5)
yum install -y httpd httpd-devel  php53 php53-mysql php53-common php53-gd php53-mbstring php53-mcrypt php53-devel php53-xml
rpm -e `rpm -qa|grep mysql` --nodeps
rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum --enablerepo=remi,remi-test install mysql mysql-server -y
echo "<?php phpinfo();?>">/var/www/html/index.php
;;
Red6|CentOS6)
yum  install -y httpd httpd-devel  php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml
rpm -e `rpm -qa|grep mysql` --nodeps
rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum --enablerepo=remi,remi-test install mysql mysql-server -y
echo "<?php phpinfo();?>">/var/www/html/index.php
;;
*)
echo "Unknown system"
;;
esac

chkconfig httpd on
chkconfig mysqld on
service httpd start
service mysqld start
service iptables stop
#Disabled SELINUX
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
ip=`ifconfig | grep "inet addr" |grep -v 127.0.0.1|awk '{print $2}'|cut -d: -f2|head -1`
echo -e "\033[32m URL：  http://$ip/index.php \033[0m"
